import { Component } from '@angular/core';

import { Platform, NavController } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Router } from '@angular/router';
import { NativeService } from './providers/NativeService';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    public native: NativeService,
    public router: Router,
    private nav: NavController
  ) {
    this.initializeApp();
    this.platform.backButton.subscribe((value) => {
      // if (this.router.url === '/login' && !GlobalData.token) {
      //     this.native.appMinimize();
      // }
      console.log('点击了后退', this.router.url);
      console.log('=============', value.register(1, () => { }));
      // this.presentAlert(JSON.stringify(this.router.url));
      // console.dir('点击了后退',JSON.stringify(this.router) );
      if (this.router.url === '/tabs/tab1' ||
        this.router.url === '/tabs/tab2' ||
        this.router.url === '/tabs/tab3' ||
        this.router.url === '/tabs/tab4'
      ) {
        this.native.appMinimize();
      }
      else {
        this.nav.pop();
      }
      
   


    });
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      this.statusBar.backgroundColorByHexString('#4D4D4D');
      // this.nav.navigateBack('ttkefu');
    });
  }
}
